package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.IcPartyApplicants;
import com.ruoyi.system.service.IIcPartyApplicantsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 入党积极分子Controller
 * 
 * @author ruoyi
 * @date 2024-07-10
 */
@Controller
@RequestMapping("/system/icPartyApplicants")
public class IcPartyApplicantsController extends BaseController
{
    private String prefix = "system/icPartyApplicants";

    @Autowired
    private IIcPartyApplicantsService icPartyApplicantsService;

    @RequiresPermissions("system:icPartyApplicants:view")
    @GetMapping()
    public String icPartyApplicants()
    {
        return prefix + "/icPartyApplicants";
    }

    /**
     * 查询入党积极分子列表
     */
    @RequiresPermissions("system:icPartyApplicants:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IcPartyApplicants icPartyApplicants)
    {
        startPage();
        List<IcPartyApplicants> list = icPartyApplicantsService.selectIcPartyApplicantsList(icPartyApplicants);
        return getDataTable(list);
    }

    /**
     * 导出入党积极分子列表
     */
    @RequiresPermissions("system:icPartyApplicants:export")
    @Log(title = "入党积极分子", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IcPartyApplicants icPartyApplicants)
    {
        List<IcPartyApplicants> list = icPartyApplicantsService.selectIcPartyApplicantsList(icPartyApplicants);
        ExcelUtil<IcPartyApplicants> util = new ExcelUtil<IcPartyApplicants>(IcPartyApplicants.class);
        return util.exportExcel(list, "入党积极分子数据");
    }

    /**
     * 新增入党积极分子
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存入党积极分子
     */
    @RequiresPermissions("system:icPartyApplicants:add")
    @Log(title = "入党积极分子", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IcPartyApplicants icPartyApplicants)
    {
        return toAjax(icPartyApplicantsService.insertIcPartyApplicants(icPartyApplicants));
    }

    /**
     * 修改入党积极分子
     */
    @RequiresPermissions("system:icPartyApplicants:edit")
    @GetMapping("/edit/{applicantId}")
    public String edit(@PathVariable("applicantId") Long applicantId, ModelMap mmap)
    {
        IcPartyApplicants icPartyApplicants = icPartyApplicantsService.selectIcPartyApplicantsByApplicantId(applicantId);
        mmap.put("icPartyApplicants", icPartyApplicants);
        return prefix + "/edit";
    }

    /**
     * 修改保存入党积极分子
     */
    @RequiresPermissions("system:icPartyApplicants:edit")
    @Log(title = "入党积极分子", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IcPartyApplicants icPartyApplicants)
    {
        return toAjax(icPartyApplicantsService.updateIcPartyApplicants(icPartyApplicants));
    }

    /**
     * 删除入党积极分子
     */
    @RequiresPermissions("system:icPartyApplicants:remove")
    @Log(title = "入党积极分子", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(icPartyApplicantsService.deleteIcPartyApplicantsByApplicantIds(ids));
    }
}
